Skip to content

fix: apply dim and italic attributes in SwingTerminal, fix conceal+dim interaction#1758

Merged
gnodet merged 3 commits into
jline:masterfrom
Elec332:screen-bold-reset
Apr 7, 2026
Merged

fix: apply dim and italic attributes in SwingTerminal, fix conceal+dim interaction#1758
gnodet merged 3 commits into
jline:masterfrom
Elec332:screen-bold-reset

Conversation

@Elec332
Copy link
Copy Markdown
Contributor

@Elec332 Elec332 commented Apr 2, 2026

Summary

Fixes two issues with attributes added in 237f60b:

  1. ScreenTerminal (HTML): When both conceal (SGR 8) and dim (SGR 2) are active, the dim formula altered the foreground color after concealment set it to the background color, breaking text hiding. Fixed by making dim an else if after conceal.
  2. SwingTerminal: The dim and italic attributes added in that commit were not implemented in the Swing renderer — only the HTML renderer handled them.

Changes

Bug fix — conceal + dim interaction (ScreenTerminal)

  • Changed if (dim) to else if (dim) after the if (conceal) block in generateSpanTag, so concealment always wins.

Feature — dim and italic support (SwingTerminal)

  • Added dim (SGR 2) rendering: halves each 4-bit RGB channel of the foreground.
  • Added italic (SGR 3) rendering: combines Font.BOLD and Font.ITALIC in a single deriveFont() call.
  • Extracted resolveColors(), dimColor(), and resolveFontStyle() from paintCell to reduce cognitive complexity from 18 to 7 (SonarCloud java:S3776 threshold is 15).

Tests

  • ScreenTerminalTest: conceal + dim interaction (verifies fg equals bg via HTML dump).
  • SwingTerminalRenderingTest (new, 16 tests): unit tests for resolveColors, dimColor, and resolveFontStyle covering defaults, inverse, conceal, dim, conceal+dim, cursor override, bold, italic, bold+italic.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed text rendering when both conceal and dim attributes are applied; conceal now properly takes precedence.
    • Improved color handling for dimmed text.
    • Enhanced font styling in terminal rendering.
  • Tests

    • Added test coverage for conceal and dim attribute interactions.
    • Added comprehensive tests for color and font style resolution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a51c6842-393f-4cc0-85c0-d0c665d4893b

📥 Commits

Reviewing files that changed from the base of the PR and between 0a0242a and 38e7e51.

📒 Files selected for processing (4)
  • builtins/src/main/java/org/jline/builtins/ScreenTerminal.java
  • builtins/src/main/java/org/jline/builtins/SwingTerminal.java
  • builtins/src/test/java/org/jline/builtins/ScreenTerminalTest.java
  • builtins/src/test/java/org/jline/builtins/SwingTerminalRenderingTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • builtins/src/main/java/org/jline/builtins/ScreenTerminal.java

📝 Walkthrough

Walkthrough

Conceal now prevents dim from altering foreground in ScreenTerminal. SwingTerminal centralizes color/font resolution (adds dim, italic handling and helpers). New unit tests validate conceal-vs-dim behavior and SwingTerminal color/font resolution.

Changes

Cohort / File(s) Summary
Screen terminal CSS generation
builtins/src/main/java/org/jline/builtins/ScreenTerminal.java
Made conceal and dim mutually exclusive in span/CSS generation: when conceal is set the foreground is set to background and dim logic is skipped.
Swing terminal rendering helpers
builtins/src/main/java/org/jline/builtins/SwingTerminal.java
Extracted color/font resolution into helpers: resolveColors, dimColor, resolveFontStyle. paintCell delegates to these; adds dim (4-bit nibble halving) and italic handling, preserves inverse/conceal/cursor precedence.
Tests
builtins/src/test/java/org/jline/builtins/ScreenTerminalTest.java, builtins/src/test/java/org/jline/builtins/SwingTerminalRenderingTest.java
Added tests: verify conceal+dim interaction in HTML dump; validate dimColor, resolveColors (FG/BG, INVERSE, CONCEAL, DIM, cursor visibility) and resolveFontStyle mappings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

bug

Poem

🐰 I nibbled at nibbles and dimmed just so,

Conceal hopped forward, told dim not to show.
I stitched fonts with a slant and a bold little grin,
Tests clap their paws — the render's now kin.
A rabbit's small patch: pixels tidy and trim.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main fixes: dim and italic attribute implementation in SwingTerminal and the conceal+dim interaction fix in ScreenTerminal.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
builtins/src/main/java/org/jline/builtins/SwingTerminal.java (1)

680-687: ⚠️ Potential issue | 🟡 Minor

Bug: Bold style is lost when both bold and italic are set.

Font.deriveFont(int style) replaces the font style rather than combining styles. When both bold and italic are true, the second call overwrites the bold style, resulting in italic-only text.

🐛 Proposed fix to combine font styles
                 // Set font style
                 Font font = terminalFont;
-                if (bold) {
-                    font = font.deriveFont(Font.BOLD);
-                }
-                if (italic) {
-                    font = font.deriveFont(Font.ITALIC);
+                int style = Font.PLAIN;
+                if (bold) {
+                    style |= Font.BOLD;
+                }
+                if (italic) {
+                    style |= Font.ITALIC;
+                }
+                if (style != Font.PLAIN) {
+                    font = font.deriveFont(style);
                 }
                 g2d.setFont(font);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@builtins/src/main/java/org/jline/builtins/SwingTerminal.java` around lines
680 - 687, The font derivation currently calls terminalFont.deriveFont twice so
the second call overwrites the first and drops the bold flag when both bold and
italic are true; instead compute a combined style int (e.g., style = (bold ?
Font.BOLD : 0) | (italic ? Font.ITALIC : 0)) and call
terminalFont.deriveFont(style) once, then pass that font to g2d.setFont; update
the code around terminalFont, bold, italic, deriveFont and g2d.setFont in
SwingTerminal accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@builtins/src/main/java/org/jline/builtins/SwingTerminal.java`:
- Around line 680-687: The font derivation currently calls
terminalFont.deriveFont twice so the second call overwrites the first and drops
the bold flag when both bold and italic are true; instead compute a combined
style int (e.g., style = (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0))
and call terminalFont.deriveFont(style) once, then pass that font to
g2d.setFont; update the code around terminalFont, bold, italic, deriveFont and
g2d.setFont in SwingTerminal accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: de01b9ac-cd30-4d41-93ad-6446ba752bbf

📥 Commits

Reviewing files that changed from the base of the PR and between cc8d538 and d5e93be.

📒 Files selected for processing (2)
  • builtins/src/main/java/org/jline/builtins/ScreenTerminal.java
  • builtins/src/main/java/org/jline/builtins/SwingTerminal.java

@gnodet gnodet changed the title fix: New ScreenTerminal attributes not being applied correctly fix: apply dim and italic attributes in SwingTerminal, fix conceal+dim interaction Apr 7, 2026
@gnodet gnodet added bug java Pull requests that update Java code labels Apr 7, 2026
@gnodet gnodet added this to the 4.0.11 milestone Apr 7, 2026
Elec332 and others added 3 commits April 7, 2026 05:02
Extract resolveColors(), dimColor(), and resolveFontStyle() from
paintCell to reduce cognitive complexity from 18 to 7 (SonarCloud
java:S3776 threshold is 15).

Add unit tests for conceal+dim interaction (conceal must win) and
for SwingTerminal color/font resolution logic.
@gnodet gnodet force-pushed the screen-bold-reset branch from 379c7b3 to 38e7e51 Compare April 7, 2026 03:03
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 7, 2026

@gnodet gnodet merged commit e3bba82 into jline:master Apr 7, 2026
11 checks passed
@Elec332 Elec332 deleted the screen-bold-reset branch April 11, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants